package com.skywolf.chem.article.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.skywolf.chem.article.entity.Article;
import com.skywolf.chem.article.entity.LiveInfo;
import com.skywolf.chem.article.pojo.LiveQueryParam;
import com.skywolf.chem.article.service.ILiveInfoService;
import com.skywolf.chem.common.sysconfig.pojo.vo.PageVO;
import com.skywolf.chem.common.sysconfig.response.RespData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 直播信息表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-06-09
 */
@RestController
@RequestMapping("/ct/article/live-info")
public class LiveInfoController {

    @Autowired
    ILiveInfoService liveInfoService;

    @ApiOperation(value = "获取直播列表-PC调用",notes = "获取直播列表-PC调用")
    @RequestMapping(value = "/getLive",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<Article> getLive(@RequestBody @Validated LiveQueryParam queryParam) {
        queryParam.setVideoType(0);
        IPage<LiveInfo> page = liveInfoService.livePageList(queryParam);
        PageVO<LiveInfo> pageVO = new PageVO<>(page);
        return RespData.success(pageVO);
    }

    @ApiOperation(value = "获取赛事回放列表-PC调用",notes = "获取赛事回放列表-PC调用")
    @RequestMapping(value = "/getReLive",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<Article> getReLive(@RequestBody @Validated LiveQueryParam queryParam) {
        queryParam.setVideoType(1);
        IPage<LiveInfo> page = liveInfoService.reLivePageList(queryParam);
        PageVO<LiveInfo> pageVO = new PageVO<>(page);
        return RespData.success(pageVO);
    }

    @ApiOperation(value = "获取直播跟回播列表-app赛事直播列表",notes = "获取直播跟回播列表-app赛事直播列表")
    @RequestMapping(value = "/getLiveList",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<LiveInfo> getLiveList(@RequestBody @Validated LiveQueryParam queryParam) {
        IPage<LiveInfo> page = liveInfoService.livePageList(queryParam);
        PageVO<LiveInfo> pageVO = new PageVO<>(page);
        return RespData.success(pageVO);
    }

    @ApiOperation(value = "内容搜索接口-搜索直播",notes = "内容搜索接口-搜索直播")
    @RequestMapping(value = "/search",method = {RequestMethod.GET,RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<LiveInfo> search(@RequestParam(value = "",required = true) String content) {
        QueryWrapper<LiveInfo> queryWrapper = new QueryWrapper<>();
        String sql="limit 0,20";
        queryWrapper.select("id", "video_title", "cover_url", "video_type","sub_title","created_time").eq("is_deleted",0).like("video_title", content).last(sql);
        List<LiveInfo> live = liveInfoService.list(queryWrapper);
        return RespData.success(live);
    }
}
